#include "view_time_1.h"
#include "view_times.h"
#include "display_ctrl.h"
#include "platform_assert.h"
// #include "view_time.inc"
#include "lfs_file_manager_auto.h"
#include "rtc.h"
#include "datetime.h"
#include "blecom.h"
#include "battery_ctrl.h"
#include "sport_his.h"
#include "display_ctrl.h"
#include "display_interface_240x240.h"
#include "datetime.h"
#include "heart_rate_interface.h"
#include "font/num_font.h"
#include "font_mngr.h"
#include "view_common.h"
#include "app_trace.h"
#include "view_time_1.inc"
#define LOG(fmt, ...) // app_trace_log(fmt "\r\n", ##__VA_ARGS__)

void view_time_1_display(void)
{
    int x = 0;
    int y = 0;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_1500_background_0_0);
    x = 100;
    y = 55;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, FILE_IMG_1541_week_mon_100_55 + disp_ctrl.com_data.i_temp[11] - 1);
    // 1540_num_percentage9x15
    x = 128 + 7;
    y = 55;
    disp_draw_user_image_num_mid_ignore_with_digit(x, y, RGB565_COLOR_BLACK, disp_ctrl.com_data.i_temp[10], 7, 2, num_N101_dig_7x15_TAB);

    // center 64 y 120

    // step
    //#warning debug
    //    disp_ctrl.com_data.i_temp[14] = 100;
    //    disp_ctrl.com_data.i_temp[2] = disp_ctrl.auto_refresh_count % 101;
    int step_percent_index = disp_ctrl.com_data.i_temp[2] * 17 / disp_ctrl.com_data.i_temp[14];
    if (step_percent_index > 17)
    {
        step_percent_index = 17;
    }
    if (step_percent_index > 0)
    {
        x = 31;
        y = 82;
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_2, x, y, FILE_IMG_1561_step_1_31_82 - 1 + step_percent_index);
    }
    x = 64;
    y = 120;
    // #warning debug
    //     disp_ctrl.com_data.i_temp[2] = 12345;
    disp_draw_user_image_num_mid_ignore(x, y, RGB565_COLOR_BLACK, disp_ctrl.com_data.i_temp[2], 7, num_N101_dig_7x15_TAB);

    //#warning debug
    //    disp_ctrl.com_data.i_temp[13] = disp_ctrl.auto_refresh_count % 101;
    int battery_percent_index = disp_ctrl.com_data.i_temp[13] * 17 / 100;
    if (battery_percent_index > 17)
    {
        battery_percent_index = 17;
    }
    if (battery_percent_index > 0)
    {
        x = 192;
        y = 82;
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_3, x, y, FILE_IMG_1581_batter_1_192_82 - 1 + battery_percent_index);
    }
    // #warning debug
    //     disp_ctrl.com_data.i_temp[13] = 90;
    x = 120 + 56 - 5;
    y = 120;
    x = disp_draw_user_image_num_mid_ignore(x, y, RGB565_COLOR_BLACK, disp_ctrl.com_data.i_temp[13], 7, num_N101_dig_7x15_TAB);

    disp_draw_user_image_ignore_color(x, y, RGB565_COLOR_BLACK, num_N111_9x15_percent);

    int heart_rate_level = get_heart_rate_level(disp_ctrl.com_data.i_temp[4]);
    //#warning debug
    //    heart_rate_level = disp_ctrl.auto_refresh_count % 6;
    if (heart_rate_level > 0)
    {
        x = 89;
        y = 146;
        _disp_show_flash_img(DISP_LFS_FILE_INDEX_4, x, y, FILE_IMG_1601_heartrate_1_89_146 - 1 + heart_rate_level);
    }
    x = 120;
    y = 179;
    // #warning debug
    //     disp_ctrl.com_data.i_temp[4] = 160;
    disp_draw_user_image_num_mid_ignore(x, y, RGB565_COLOR_BLACK, disp_ctrl.com_data.i_temp[4], 7, num_N101_dig_7x15_TAB);

    if (disp_ctrl.loop_cnt == 0)
    {
        disp_ctrl.com_data.i_temp[22] = (RTCGetSeconds() % 60) * 6;
        uint16_t temp16 = get_present_day_minute();
        disp_ctrl.com_data.i_temp[23] = (temp16 / 2) / 6 * 6 % 360; //时针的角度
        disp_ctrl.com_data.i_temp[24] = (temp16 * 6) / 6 * 6 % 360; //分针的角度
    }
    // #warning debug
    // disp_ctrl.com_data.i_temp[23] = (disp_ctrl.com_data.i_temp[22] + 90) % 360;
    // disp_ctrl.com_data.i_temp[24] = (disp_ctrl.com_data.i_temp[22] + 180) % 360;
    disp_draw_img_rotate(gImage_hour, 0, 83 - 0, (120 << 16) | 120, disp_ctrl.com_data.i_temp[23]);    //-3
    disp_draw_img_rotate(gImage_minute, 0, 112 - 0, (120 << 16) | 120, disp_ctrl.com_data.i_temp[24]); //-7
    disp_draw_img_rotate(gImage_second, 0, 156 - 40, (120 << 16) | 120, disp_ctrl.com_data.i_temp[22]);

    x = 110;
    y = 109;
    disp_draw_user_image_filter_color(x, y, bmp_time_1_center);
}
